﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DetailNguoiDung.ascx.cs"
    Inherits="Viewer.NguoiDung.UserControls.Detail" %>
<%@ Register Src="~/NguoiDung/UserControl/UCThemToChuc.ascx" TagName="UCThemToChuc"
    TagPrefix="uc1" %>
<%@ Register Src="~/NguoiDung/UserControl/UCThemModule.ascx" TagName="UCThemModule"
    TagPrefix="uc1" %>
<%@ Register Src="~/NguoiDung/UserControl/UCThemNhomNguoiDung.ascx" TagName="UCThemNhomNguoiDung"
    TagPrefix="uc1" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<link href="../../resources/css/main.css" rel="stylesheet" type="text/css" />
<ext:XScript ID="XScript1" runat="server">
    <script type="text/javascript" >
      function grdNhomNguoiDung_Command(command, record) {
              if (command == 'Delete') {
               
                Ext.MessageBox.show({
                   title: 'Confirm',
                   msg: 'Bạn có chắc chắn xóa record này ko?',
                   icon: Ext.MessageBox.QUESTION,
                   buttons: Ext.MessageBox.YESNO,
                   fn: function(btn)
                   {
                    if(btn.toLowerCase()=='yes')
                    {
                        //Do Yes
                        #{storeNhomNguoiDung}.remove(record);
                        #{storeThemNhomNguoiDung}.add(record);
                        #{storeThemNhomNguoiDung}.sort('TenNhomNguoiDung', 'ASC');
               
                      }
                  }
        });
            }
        }
       function grdNhomquyen_Command(command, record) {
              if (command == 'Delete') { 
                Ext.MessageBox.show({
                   title: 'Confirm',
                   msg: 'Bạn có chắc chắn xóa record này ko?',
                   icon: Ext.MessageBox.QUESTION,
                   buttons: Ext.MessageBox.YESNO,
                   fn: function(btn)
                   {
                    if(btn.toLowerCase()=='yes')
                    {
                        //Do Yes
                        #{storeNhomquyen}.remove(record);
                        #{storeToChuc}.add(record);
                        #{storeToChuc}.sort('Name', 'ASC');
               
                      }
                  }
        });
            }
        }
          function grdChucNang_Command(command, record) {
              if (command == 'Delete') { 
                Ext.MessageBox.show({
                   title: 'Confirm',
                   msg: 'Bạn có chắc chắn xóa record này ko?',
                   icon: Ext.MessageBox.QUESTION,
                   buttons: Ext.MessageBox.YESNO,
                   fn: function(btn)
                   {
                    if(btn.toLowerCase()=='yes')
                    {
                        //Do Yes
                        #{storeModule_NhomQuyen}.remove(record);
                        #{storeModule}.add(record);
                        #{storeModule}.sort('Name', 'ASC');
               
                      }
                  }
        });
            }
        }
        function GetToChucIds()
        {
            var msg = [];
            var records =#{grdNhomquyen}.store.getRange();
            Ext.each(records, function (record) {
                msg.push(record.id);
		    });
		    return msg.join(",");
        }
          function GetModuleIds()
        {
            var msg = [];
            var records =#{grdChucNang}.store.getRange();
            Ext.each(records, function (record) {
                msg.push(record.id);
		    });
		    return msg.join(",");
        }
           function GetNhomNguoiDungIds()
        {
            var msg = [];
            var records =#{grdNhomNguoiDung}.store.getRange();
            Ext.each(records, function (record) {
                msg.push(record.id);
		    });
		    return msg.join(",");
        }
        var prepare = function (grid, toolbar, rowIndex, record) {
            var firstButton = toolbar.items.get(0);           
            if(#{hdDialogType}.getValue()=='Detail') {
                firstButton.setDisabled(true);
            }
        }    
     
    </script>
</ext:XScript>
<ext:Window ID="wdDetail" runat="server" Width="600" AutoHeight="true" Modal="true"
    Closable="false" Hidden="true" HideBorders="True" Border="false" Plain="true"
    Resizable="false" Frame="false" Title="View Detail" Icon="User">
    <Items>
        <ext:Hidden ID="hdDialogType" runat="server" />
        <ext:Hidden ID="__ToChucIds" runat="server" />
        <ext:Hidden ID="__ModuleIds" runat="server" />
        <ext:Hidden ID="__NhomNguoiDungIds" runat="server" />
        <ext:TabPanel ID="TabPanel1" runat="server" Title="TabPanel" ActiveTabIndex="0" Border="false"
            AutoFocus="true" Closable="true" BodyStyle="background-color: white; border: 1px solid #AABBCC;  border-top: none;">
            <Items>
                <ext:Panel ID="Panel1" runat="server" Frame="true" Height="200px" Title="Thông tin người dùng"
                    Icon="Information" BodyStyle="background-color: white;">
                    <Content>
                        <table>
                            <tr style="display: none;">
                                <td>
                                    Người dùng ID
                                </td>
                                <td style="padding-right:3px;padding-left:3px;">
                                    <ext:TextField ID="txtId" runat="server" Disabled="true" Width="150" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Tên đăng nhập
                                </td>
                                <td style="padding-right:3px;padding-left:3px;"> 
                                <ext:Hidden ID="hdFullName" runat="server" />
                                    <ext:TextField ID="txtFullName" runat="server" Width="150" />
                                </td>
                                <td>
                                    <ext:Button ID="btnCheck" runat="server" Text="Kiểm tra tồn tại" Icon="Zoom">
                                        <Listeners>
                                            <Click Handler="Ext.net.Mask.show();
                                             if(#{txtFullName}.getValue().trim()=='')
                                                {
                                                    Ext.MessageBox.alert('Message', 'Bạn chưa nhập tên !');
                                                    #{txtFullName}.focus();
                                                    Ext.net.Mask.hide();
                                                    return false;
                                                }
                                                else
                                                {
                                                     #{DirectMethods}.CheckTonTai(#{txtFullName}.getValue());
                                                  }" />
                                        </Listeners>
                                    </ext:Button>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Mật khẩu
                                </td>
                                <td style="padding-right:3px;padding-left:3px;">
                                    <ext:TextField ID="txtPass" runat="server" Width="150" InputType="Password" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Nhập lại mật khẩu
                                </td>
                                <td style="padding-right:3px;padding-left:3px;">
                                    <ext:TextField ID="txtConfirmPass" runat="server" Width="150" InputType="Password" />
                                </td>
                            </tr>
                        </table>
                    </Content>
                </ext:Panel>
                <ext:Panel ID="Panel2" runat="server" Frame="true" Height="200px" Title="Nhóm Quyền Tổ chức"
                    Icon="ApplicationViewTile" BodyStyle="background-color: transparent;">
                    <Items>
                        <ext:GridPanel ID="grdNhomquyen" runat="server" Height="490" AutoExpandColumn="TenNhomQuyenByToChuc"
                            MonitorResize="true" AutoWidth="true">
                            <ColumnModel ID="ColumnModel1" runat="server">
                                <Columns>
                                    <ext:Column Header="Id" DataIndex="NhomQuyenByToChucID" Width="70" />
                                    <ext:Column Header="Tên tổ chức" DataIndex="TenNhomQuyenByToChuc" />
                                    <ext:Column Header="Ghi chú" DataIndex="GhiChu" Width="130">
                                    </ext:Column>
                                    <ext:CommandColumn Width="50">
                                        <Commands>
                                            <ext:GridCommand Icon="Delete" CommandName="Delete" Text="Xóa">
                                            </ext:GridCommand>
                                        </Commands>
                                        <PrepareToolbar Fn="prepare" />
                                    </ext:CommandColumn>
                                </Columns>
                            </ColumnModel>
                            <Listeners>
                                <Command Handler="grdNhomquyen_Command(command,record);" />
                            </Listeners>
                            <SelectionModel>
                                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                            </SelectionModel>
                            <Store>
                                <ext:Store ID="storeNhomquyen" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="NhomQuyenByToChucID">
                                            <Fields>
                                                <ext:RecordField Name="NhomQuyenByToChucID" />
                                                <ext:RecordField Name="TenNhomQuyenByToChuc" />
                                                <ext:RecordField Name="GhiChu" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <TopBar>
                                <ext:Toolbar ID="Toolbar3" runat="server">
                                    <Items>
                                        <ext:Button runat="server" Icon="Add" ID="btnShowDialogAddNguoiDung" Text="Thêm tổ chức">
                                            <Listeners>
                                                <Click Handler="#{DirectMethods}.ShowDialogUC('ToChuc');"></Click>
                                            </Listeners>
                                        </ext:Button>
                                    </Items>
                                </ext:Toolbar>
                            </TopBar>
                        </ext:GridPanel>
                    </Items>
                </ext:Panel>
                <ext:Panel ID="Panel3" runat="server" Frame="true" Height="200px" Title="Nhóm Quyền Chức năng"
                    Icon="BrickAdd" BodyStyle="background-color: transparent;">
                    <Items>
                        <ext:GridPanel ID="grdChucNang" runat="server" Height="490" AutoExpandColumn="TenNhomQuyenByModule"
                            MonitorResize="true" AutoWidth="true">
                            <ColumnModel ID="ColumnModel2" runat="server">
                                <Columns>
                                    <ext:Column Header="Id" DataIndex="NhomQuyenByModuleID" Width="70" />
                                    <ext:Column Header="Tên" DataIndex="TenNhomQuyenByModule" />
                                    <ext:Column Header="Ghi chú" DataIndex="GhiChu" Width="130">
                                    </ext:Column>
                                    <ext:CommandColumn Width="50">
                                        <Commands>
                                            <ext:GridCommand Icon="Delete" CommandName="Delete" Text="Xóa">
                                            </ext:GridCommand>
                                        </Commands>
                                        <PrepareToolbar Fn="prepare" />
                                    </ext:CommandColumn>
                                </Columns>
                            </ColumnModel>
                            <SelectionModel>
                                <ext:RowSelectionModel ID="RowSelectionModel2" runat="server" SingleSelect="true" />
                            </SelectionModel>
                            <Store>
                                <ext:Store ID="storeModule_NhomQuyen" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="NhomQuyenByModuleID">
                                            <Fields>
                                                <ext:RecordField Name="NhomQuyenByModuleID" />
                                                <ext:RecordField Name="TenNhomQuyenByModule" />
                                                <ext:RecordField Name="GhiChu" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <Listeners>
                                <Command Handler="grdChucNang_Command(command,record);" />
                            </Listeners>
                            <TopBar>
                                <ext:Toolbar ID="Toolbar2" runat="server">
                                    <Items>
                                        <ext:Button runat="server" Icon="Add" ID="Button2" Text="Thêm chức năng">
                                            <Listeners>
                                                <Click Handler="#{DirectMethods}.ShowDialogUC('ChucNang');"></Click>
                                            </Listeners>
                                        </ext:Button>
                                    </Items>
                                </ext:Toolbar>
                            </TopBar>
                        </ext:GridPanel>
                    </Items>
                </ext:Panel>
                <ext:Panel ID="Panel4" runat="server" Frame="true" Height="200px" Title="Nhóm người dùng"
                    Icon="BrickAdd" BodyStyle="background-color: transparent;">
                    <Items>
                        <ext:GridPanel ID="grdNhomNguoiDung" runat="server" Height="490" MonitorResize="true"
                            AutoWidth="true">
                            <ColumnModel ID="ColumnModel3" runat="server">
                                <Columns>
                                    <ext:Column Header="Nhóm người dùng" DataIndex="TenNhomNguoiDung" Width="150" />
                                    <%--<ext:Column Header="Loại nhóm người dùng" DataIndex="TenLoaiNhomNguoiDung" />--%>
                                    <ext:Column Header="Ghi chú" DataIndex="GhiChu" />
                                    <ext:CommandColumn Width="50">
                                        <Commands>
                                            <ext:GridCommand Icon="Delete" CommandName="Delete" Text="Xóa">
                                            </ext:GridCommand>
                                        </Commands>
                                        <PrepareToolbar Fn="prepare" />
                                    </ext:CommandColumn>
                                </Columns>
                            </ColumnModel>
                            <SelectionModel>
                                <ext:RowSelectionModel ID="RowSelectionModel3" runat="server" SingleSelect="true" />
                            </SelectionModel>
                            <Store>
                                <ext:Store ID="storeNhomNguoiDung" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="NhomNguoiDungID">
                                            <Fields>
                                                <ext:RecordField Name="TenNhomNguoiDung" />
                                                <ext:RecordField Name="NhomNguoiDungID" />
                                                <ext:RecordField Name="GhiChu" />
                                                <%--<ext:RecordField Name="TenLoaiNhomNguoiDung" />--%>
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <Listeners>
                                <Command Handler="grdNhomNguoiDung_Command(command,record);" />
                            </Listeners>
                            <TopBar>
                                <ext:Toolbar ID="Toolbar4" runat="server">
                                    <Items>
                                        <ext:Button runat="server" Icon="Add" ID="Button3" Text="Thêm nhóm người dùng">
                                            <Listeners>
                                                <Click Handler="#{DirectMethods}.ShowDialogUC('NhomNguoiDung');"></Click>
                                            </Listeners>
                                        </ext:Button>
                                    </Items>
                                </ext:Toolbar>
                            </TopBar>
                        </ext:GridPanel>
                    </Items>
                </ext:Panel>
            </Items>
        </ext:TabPanel>
    </Items>
    <BottomBar>
        <ext:Toolbar ID="Toolbar1" runat="server">
            <Items>
                <ext:ToolbarFill ID="ToolbarFill1" runat="server">
                </ext:ToolbarFill>
                <ext:Hidden ID="hdCheck" runat="server" />
                <ext:Button ID="btnSave" runat="server" Text="Lưu" Icon="Disk">
                    <Listeners>
                        <Click Handler="
                        Ext.net.Mask.show();
                                    //Validate
                                     #{__ToChucIds}.setValue(GetToChucIds());
                                       #{__ModuleIds}.setValue(GetModuleIds());
                                         #{__NhomNguoiDungIds}.setValue(GetNhomNguoiDungIds());
                                    if(#{txtFullName}.getValue().trim()=='')
                                    {
                                   Ext.net.Mask.hide();
                                        Ext.MessageBox.alert('Message', 'Bạn chưa nhập tên !');
                                        #{txtFullName}.focus();
                                        return false;
                                    }
                                      if(#{txtPass}.getValue().trim()!=#{txtConfirmPass}.getValue().trim())
                                    {
                                  Ext.net.Mask.hide();
                                        Ext.MessageBox.alert('Message', 'Mật khẩu không trùng nhau!');
                                        #{txtConfirmPass}.focus();
                                        return false;
                                    }
                                    if( #{grdNhomNguoiDung}.getStore().getTotalCount()==0)
                                    {
                                    Ext.net.Mask.hide();
                                        Ext.MessageBox.alert('Message', 'Xin vui lòng chọn nhóm người dùng !');                                       
                                        return false;                                       
                                    }
                                " />
                    </Listeners>
                    <DirectEvents>
                        <Click OnEvent="btnSave_Click">
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="Button1" runat="server" Text="Đóng" Icon="Cancel">
                    <Listeners>
                        <Click Handler="#{wdDetail}.hide();" />
                    </Listeners>
                </ext:Button>
            </Items>
        </ext:Toolbar>
    </BottomBar>
</ext:Window>
<uc1:UCThemToChuc ID="UCThemToChuc" runat="server" />
<uc1:UCThemModule ID="UCThemModule" runat="server" />
<uc1:UCThemNhomNguoiDung ID="UCThemNhomNguoiDung" runat="server" />
